package t4tools.splittingObjects.order;

import java.util.Comparator;
import java.util.Map;

import t4tools.splittingObjects.model.Cell;
import t4tools.splittingObjects.model.Row;

public class DefaultAlphabeticalComparator implements Comparator<Row> {

	public int compare(Row o1, Row o2) {
		for (Map.Entry<String, Cell> entry : o1.getCells().entrySet()) {
			String value1 = null;
			String value2 = null;
			if (entry.getValue() != null) {
				value1 = entry.getValue().getStringValue();
			}
			Cell cell = o2.getCell(entry.getKey());
			if (cell != null) {
				value2 = cell.getStringValue();
			}
			int result = (value1 != null && value2 != null) ? value1.compareTo(value2) : 0;
			if (result != 0) {
				return result;
			}
		}
		return 0;
	}

}
